Skip to content

发送字符串2 - SendString2

函数简介

向指定窗口发送文本数据(UTF-8)。与 SendString 的核心差异:发送前强制异步打开中文输入法(切换布局 + 打开 IME)。

字符投递使用 PostMessageW(WM_CHAR);Edit/RichEdit 仍优先 EM_REPLACESEL

风险提示

部分程序(游戏、金融客户端等)对布局切换 / 打开 IME 过敏,可能导致卡死或无响应。默认场景请优先使用 SendString;仅当目标窗必须开输入法才能正确输入中文时再用本接口。

接口名称

SendString2

DLL调用

int SendString2(long ola, long hwnd, string str);

参数说明

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
hwnd长整数型目标窗口句柄。为 0 时使用当前 绑定窗口
str字符串要发送的文本数据(UTF-8)。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int ret = ola.SendString2(hwnd, "你好");
csharp
using OLAPlug;

var ola = new OLAPlugServer();
int ret = ola.SendString2(hwnd, "你好");
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
ret = ola.SendString2(hwnd, "你好")
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
int ret = ola.SendString2(hwnd, "你好");
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
ret := ola.SendString2(hwnd, "你好")
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let ret = ola.send_string2(&hwnd, "你好");
cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.SendString2(hwnd, "你好")
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.SendString2(hwnd, "你好")
text
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.SendString2(hwnd, “你好”)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.SendString2(hwnd, "你好");
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.SendString2(hwnd, "你好")
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int32_t ret = ola.SendString2(hwnd, "你好");

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
SendString2(instance, hwnd, "你好");
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int SendString2(long ola, long hwnd, string str);

long instance = CreateCOLAPlugInterFace();
SendString2(instance, hwnd, "你好");
python
from ctypes import CDLL, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.SendString2(instance, hwnd, "你好".encode("utf-8"))

返回值

返回值说明
1成功。
0失败。

注意事项

项目说明
与 SendString 差异仅本接口会主动打开输入法;SendString 不打开。
卡死风险布局切换通过异步 PostMessage 完成,仍可能导致个别程序异常,请先小范围验证。
发送间隔字符间隔受 SetConfig 中键盘延时(如 KeyDownInterval)影响。